const baseUrl = 'http://lingdian.h8m.cn/index.php/api'  //请求接口地址
const httpRequest = (url, method, data) => {
	let meth = method.toUpperCase();//小写改为大写
	if (!data) {
		data = {}
	}
	
	if(getApp().globalData.token){
		data['token'] = getApp().globalData.token; //token
	}
	
    let httpDefaultOpts = {
        url: baseUrl + url,
        data: data,
        method: meth,
		header:{
			'X-Requested-With': 'XMLHttpRequest',
			'content-type': meth == 'POST' ? 'application/x-www-form-urlencoded' : 'application/json',
		},
        dataType: 'json',
    }
    return new Promise(function(resolve, reject) {
        uni.request(httpDefaultOpts).then(
            (res) => {
			
				if(res[1].data.code == 1){//成功返回
					resolve(res[1])
				}else{//错误信息
					uni.showToast({
						title:res[1].data.msg,
						icon:'none' 
					})
                    //resolve(res[1]) //错误信息返不返回 看个人情况
				}
            }
        ).catch(
            (response) => {
                reject(response)
            }
        )
    })
};
 
export default {
	baseUrl,
	httpRequest				
}
